

#include	"SysConfig.h"
#include	"Define.h"

#include	"UI_Main.h"
#include	"Audio.h"
#include	"Display.h"
#ifdef  ST7565P
#include	"ST7565P.h"
#endif

#ifdef BLUETOOTH
#include	"Bluetooth.h"
#ifdef  PHONE_BOOK
#include	"PhoneBook.h"
#endif
#endif

extern unsigned char ucDISP_Blink;
extern void DISP_MainText_ClockSub(unsigned char ucHour, unsigned char ucMin, unsigned char ucOpt);
extern void DISP_Display_SubText_ClockSub(unsigned char ucHour);

extern unsigned char ucDISP_ScrollEnable;
extern UI_MENU_ID	ucMenuID;
extern unsigned char ucMENU_SetHour;
extern unsigned char ucMENU_SetMin;
extern unsigned char ucAUDIO_Bass;
extern unsigned char ucAUDIO_Middle;
extern unsigned char ucAUDIO_Treble;
extern unsigned char ucAUDIO_Fader;
extern unsigned char ucAUDIO_Balance;
extern UI_EQ_MODE ucAUDIO_Equalizer;
extern unsigned char ucAUDIO_BeepEnable;
extern unsigned char ucAUDIO_Loud;

extern unsigned char ucDISP_Buf[12];
extern unsigned short usMENU_Timer100msec;
extern unsigned char ucMENU_CurNo;

#ifdef  BLUETOOTH
extern unsigned char ucBT_ConnectRequestIndex;
extern unsigned char ucPBAP_CallHistoryCnt;
extern unsigned char ucBT_Volume;
extern unsigned char ucBT_DeviceCnt;
extern BT_DEVICE	sBT_BDList[BT_DEVICE_NUM];
extern PBAP_LIST	sPBAP_CallHistory[PBAP_NUMBER_CALL_HISTORY];
extern unsigned char BT_GetBDIndexByOrder(unsigned char ucOrder);
extern unsigned char Bluetooth_DISP_CallNumberSize(unsigned char *ucNum, unsigned char ucSize);
extern unsigned char Bluetooth_DISP_GetStringLentgh(unsigned char *ucBuf, unsigned char Lfn, unsigned short ucSize);
extern unsigned char BT_ConnectStatus(void);
#endif

void UI_DMENU_ClockSet_AM_PM(unsigned char ucHour)
{
	unsigned char ucBuf[3];

	ucBuf[0] = 0x00;
	if	(ucHour < 12)
	{
		ucBuf[1] = 'A';
		ucBuf[2] = 'M';
	}
	else
	{
		ucBuf[1] = 'P';
		ucBuf[2] = 'M';
	}
				
#ifdef  ST7565P
	ST7565_UpdateSubDisplayData(&ucBuf[0]); 
#endif

#ifdef  PT6524
	ucDISP_Buf[0] = ucBuf[0];
	ucDISP_Buf[1] = ucBuf[1];
	ucDISP_Buf[2] = ucBuf[2];	 
#endif
}

void UI_DMENU_ClockSetHour(void)
{
	UI_DMENU_ClockSet_AM_PM(ucMENU_SetHour);
	if  (ucDISP_Blink == 1)
	{
		DISP_MainText_ClockSub(ucMENU_SetHour, ucMENU_SetMin, 0x01);
	}
	else
	{
		DISP_MainText_ClockSub(ucMENU_SetHour, ucMENU_SetMin, 0xFF);
	}
}

void UI_DMENU_ClockSetMin(void)
{
	UI_DMENU_ClockSet_AM_PM(ucMENU_SetHour);
	if  (ucDISP_Blink == 1)
	{
		DISP_MainText_ClockSub(ucMENU_SetHour, ucMENU_SetMin, 0x02);
	}
	else
	{
		DISP_MainText_ClockSub(ucMENU_SetHour, ucMENU_SetMin, 0xFF);
	}
}

void UI_DISP_AudioValToString(unsigned char *ucBuf, unsigned char ucData, unsigned char ucDefault, unsigned char ucMode)
{
	if  (ucMode == 1)
	{
		if  (ucData == ucDefault)
		{
			*ucBuf = ' ';
			*(ucBuf + 1) = '0';
		}
		else if  (ucData < ucDefault)
		{
			ucData = ucDefault - ucData;
			*ucBuf = '-';
			*(ucBuf + 1) = ucData + '0';
		}
		else if  (ucData > ucDefault)
		{
			*ucBuf = '+';
			*(ucBuf + 1) = (ucData - ucDefault) + '0';
		}
	}
	else
	{ 

		if  (ucData == ucDefault)
		{
			*ucBuf = '0';	
		}
		else if  (ucData < ucDefault)	//0 ~ 14
		{
			ucData = ucDefault - ucData;
			*ucBuf = (ucData / 10) + '0';
			*(ucBuf + 1) = (ucData % 10) + '0'; 
		}
		else if  (ucData > ucDefault)
		{			
			ucData = (ucData - ucDefault); //16~30
			*ucBuf = (ucData / 10) + '0';
			*(ucBuf + 1) = (ucData % 10) + '0';		
		}
	}	
}

void UI_DMENU_Bass(void)
{
#ifdef  ST7565P

	unsigned char ucBuf[10];

	memset(&ucBuf[0], ' ', 10);

	ucBuf[0] = 'B';
	ucBuf[1] = 'A';
	ucBuf[2] = 'S';

	UI_DISP_AudioValToString(&ucBuf[4],ucAUDIO_Bass,BASS_DEFAULT,1);
	
	ST7565_UpdateDisplayData(7, ucBuf[0]);
	ST7565_UpdateDisplayData(16, ucBuf[1]);
	ST7565_UpdateDisplayData(27, ucBuf[2]);
	
	if	(ucBuf[4] == ' ')
	{
		ST7565_UpdateDisplayData(58, ucBuf[5]);	
	}
	else if  (ucBuf[4] == '-')
	{
		ST7565_UpdateDisplayData(59, ucBuf[4]);
		ST7565_UpdateDisplayData(65, ucBuf[5]);	
	}
	else
	{
		ST7565_UpdateDisplayData(58, ucBuf[4]);
		ST7565_UpdateDisplayData(65, ucBuf[5]);	
	}			
#endif
#ifdef  PT6524
	memcpy(&ucDISP_Buf[4], "BAS", 3);

	UI_DISP_AudioValToString(&ucDISP_Buf[9],ucAUDIO_Bass,BASS_DEFAULT,1);
	
#endif
	
}

void UI_DMENU_Middle(void)
{
#ifdef  ST7565P

	unsigned char ucBuf[10];
	
	memset(&ucBuf[0], ' ', 10);

	ucBuf[0] = 'M';
	ucBuf[1] = 'I';
	ucBuf[2] = 'D';

	UI_DISP_AudioValToString(&ucBuf[4],ucAUDIO_Middle,MIDDLE_DEFAULT,1);
	
	ST7565_UpdateDisplayData(7, ucBuf[0]);
	ST7565_UpdateDisplayData(18, ucBuf[1]);
	ST7565_UpdateDisplayData(21, ucBuf[2]);
	
	if  (ucBuf[4] == ' ')
	{
		ST7565_UpdateDisplayData(58, ucBuf[5]);	
	}
	else if  (ucBuf[4] == '-')
	{
		ST7565_UpdateDisplayData(59, ucBuf[4]);
		ST7565_UpdateDisplayData(65, ucBuf[5]);	
	}
	else
	{
		ST7565_UpdateDisplayData(58, ucBuf[4]);
		ST7565_UpdateDisplayData(65, ucBuf[5]);	
	}			
#endif
#ifdef  PT6524
	memcpy(&ucDISP_Buf[4], "MID", 3);

	UI_DISP_AudioValToString(&ucDISP_Buf[9],ucAUDIO_Middle,MIDDLE_DEFAULT,1);
	
#endif
	
}

void UI_DMENU_Treble(void)
{
#ifdef  ST7565P
	unsigned char ucBuf[10];

	memset(&ucBuf[0], ' ', 10);

	ucBuf[0] = 'T';
	ucBuf[1] = 'R';
	ucBuf[2] = 'E';

	UI_DISP_AudioValToString(&ucBuf[4],ucAUDIO_Treble,TREBLE_DEFAULT,1);	
	
	ST7565_UpdateDisplayData(7, ucBuf[0]);
	ST7565_UpdateDisplayData(16, ucBuf[1]);
	ST7565_UpdateDisplayData(25, ucBuf[2]);
	
	if  (ucBuf[4] == ' ')
	{
		ST7565_UpdateDisplayData(58, ucBuf[5]);	
	}
	else if  (ucBuf[4] == '-')
	{
		ST7565_UpdateDisplayData(59, ucBuf[4]);
		ST7565_UpdateDisplayData(65, ucBuf[5]);	
	}
	else
	{
		ST7565_UpdateDisplayData(58, ucBuf[4]);
		ST7565_UpdateDisplayData(65, ucBuf[5]);	
	}			
#endif
#ifdef  PT6524
	memcpy(&ucDISP_Buf[4], "TRE", 3);
	
	UI_DISP_AudioValToString(&ucDISP_Buf[9],ucAUDIO_Treble,TREBLE_DEFAULT,1);	
	
#endif
}

void UI_DMENU_Fader(void)
{
#ifdef  ST7565P
	unsigned char ucBuf[10];

	memset(&ucBuf[0], ' ', 10);		

	if	(ucAUDIO_Fader == FADER_DEFAULT)
	{
		ucBuf[0] = 'F';
		ucBuf[1] = 'A';
		ucBuf[2] = 'D';
		ucBuf[3] = ' ';

		UI_DISP_AudioValToString(&ucBuf[4],ucAUDIO_Fader,FADER_DEFAULT,0);
		ucBuf[6] = 0x00;
		
		ST7565_UpdateDisplayData(7, ucBuf[0]);
		ST7565_UpdateDisplayData(15, ucBuf[1]);
		ST7565_UpdateDisplayData(26, ucBuf[2]);
		ST7565_UpdateDisplayString(58, &ucBuf[4], 0);
	}
	else if  (ucAUDIO_Fader < FADER_DEFAULT)		
	{	
		ucBuf[0] = 'R';
		ucBuf[1] = 'E';
		ucBuf[2] = 'A';
		ucBuf[3] = 'R';
		ucBuf[4] = ' ';

		UI_DISP_AudioValToString(&ucBuf[5],ucAUDIO_Fader,FADER_DEFAULT,0);
		ucBuf[7] = 0x00;
		
		ST7565_UpdateDisplayData(7, ucBuf[0]);
		ST7565_UpdateDisplayData(15, ucBuf[1]);
		ST7565_UpdateDisplayData(25, ucBuf[2]);
		ST7565_UpdateDisplayData(37, ucBuf[3]);
		ST7565_UpdateDisplayString(58, &ucBuf[5], 0);
	}
	else
	{
		ucBuf[0] = 'F';
		ucBuf[1] = 'R';
		ucBuf[2] = 'O';
		ucBuf[3] = 'N';
		ucBuf[4] = 'T';
		ucBuf[5] = ' ';

		UI_DISP_AudioValToString(&ucBuf[6],ucAUDIO_Fader,FADER_DEFAULT,0);
 		ucBuf[8] = 0x00;
		
		ST7565_UpdateDisplayData(7, ucBuf[0]);
		ST7565_UpdateDisplayData(15, ucBuf[1]);
		ST7565_UpdateDisplayData(24, ucBuf[2]);
		ST7565_UpdateDisplayData(34, ucBuf[3]);
		ST7565_UpdateDisplayData(43, ucBuf[4]);
		ST7565_UpdateDisplayString(58, &ucBuf[6], 0);

	}
#endif
#ifdef  PT6524
	memcpy(&ucDISP_Buf[4], "FAD", 3);

	UI_DISP_AudioValToString(&ucDISP_Buf[9],ucAUDIO_Fader,FADER_DEFAULT,0);
	
	if	(ucAUDIO_Fader == FADER_DEFAULT)
	{
		ucDISP_Buf[9] = ' ';
		ucDISP_Buf[10] = '0';
	}
	else if  (ucAUDIO_Fader < FADER_DEFAULT)		
	{
		ucDISP_Buf[8] = 'R';		
	}	
	else
	{
		ucDISP_Buf[8] = 'F';	
	}
#endif 
}

void UI_DMENU_Balance(void)
{
#ifdef  ST7565P
	unsigned char ucBuf[10];

	memset(&ucBuf[0], ' ' , 10);
	
	if  (ucAUDIO_Balance== BALANCE_DEFAULT)
	{
		ucBuf[0] = 'B';
		ucBuf[1] = 'A';
		ucBuf[2] = 'L';
		ucBuf[3] = ' ';

		UI_DISP_AudioValToString(&ucBuf[4],ucAUDIO_Balance,BALANCE_DEFAULT,0);
		ucBuf[6] = 0x00;
		
		ST7565_UpdateDisplayData(7, ucBuf[0]);
		ST7565_UpdateDisplayData(16, ucBuf[1]);
		ST7565_UpdateDisplayData(27, ucBuf[2]);
		ST7565_UpdateDisplayString(58, &ucBuf[4], 0);
	}

	else if  (ucAUDIO_Balance < BALANCE_DEFAULT)		
	{
		ucBuf[0] = 'L';
		ucBuf[1] = 'E';
		ucBuf[2] = 'F';
		ucBuf[3] = 'T';
		ucBuf[4] = ' ';

		UI_DISP_AudioValToString(&ucBuf[5],ucAUDIO_Balance,BALANCE_DEFAULT,0);
		ucBuf[7] = 0x00;
		
		ST7565_UpdateDisplayData(7, ucBuf[0]);
		ST7565_UpdateDisplayData(15, ucBuf[1]);
		ST7565_UpdateDisplayData(24, ucBuf[2]);
		ST7565_UpdateDisplayData(32, ucBuf[3]);
		ST7565_UpdateDisplayString(58, &ucBuf[5], 0);
	}
	else
	{
		ucBuf[0] = 'R';
		ucBuf[1] = 'I';
		ucBuf[2] = 'G';
		ucBuf[3] = 'H';
		ucBuf[4] = 'T';
		ucBuf[5] = ' ';

		UI_DISP_AudioValToString(&ucBuf[6],ucAUDIO_Balance,BALANCE_DEFAULT,0);
		ucBuf[8] = 0x00;
		
		ST7565_UpdateDisplayData(7, ucBuf[0]);
		ST7565_UpdateDisplayData(16, ucBuf[1]);
		ST7565_UpdateDisplayData(19, ucBuf[2]);
		ST7565_UpdateDisplayData(29, ucBuf[3]);
		ST7565_UpdateDisplayData(38, ucBuf[4]);
		ST7565_UpdateDisplayString(58, &ucBuf[6], 0);
	}
#endif
#ifdef  PT6524
	memcpy(&ucDISP_Buf[4], "BAL", 3);

	UI_DISP_AudioValToString(&ucDISP_Buf[9],ucAUDIO_Balance,BALANCE_DEFAULT,0);
	
	if	(ucAUDIO_Balance == BALANCE_DEFAULT)
	{
		ucDISP_Buf[9] = ' ';
		ucDISP_Buf[10] = '0';
	}
	else if  (ucAUDIO_Balance < BALANCE_DEFAULT)		
	{
		ucDISP_Buf[8] = 'L';		
	}	
	else
	{
		ucDISP_Buf[8] = 'R';	
	}
#endif
}

void UI_DMENU_Loudess(void)
{
#ifdef  ST7565P
	unsigned char ucBuf[10];
	
	memset(&ucBuf[0], ' ', 10);

	ucBuf[0] = 'L';
	ucBuf[1] = 'O';
	ucBuf[2] = 'U';
	ucBuf[3] = 'D';

	if 	(ucAUDIO_Loud == 0)
	{
		ucBuf[5] = 'O';
		ucBuf[6] = 'F';
		ucBuf[7] = 'F';
		ucBuf[8] = 0x00;
	}
	else
	{
		ucBuf[5] = 'O';
		ucBuf[6] = 'N';
		ucBuf[7] = 0x00;
	}
	
	ST7565_UpdateDisplayData(7, ucBuf[0]);
	ST7565_UpdateDisplayData(15, ucBuf[1]);
	ST7565_UpdateDisplayData(25, ucBuf[2]);
	ST7565_UpdateDisplayData(34, ucBuf[3]);
	ST7565_UpdateDisplayString(48, &ucBuf[5], 0);
#endif
#ifdef  PT6524
	memcpy(&ucDISP_Buf[4], "LOUD", 4);

	if	(ucAUDIO_Loud == 0)
	{
		ucDISP_Buf[9] = 'O';
		ucDISP_Buf[10] = 'F';
		ucDISP_Buf[11] = 'F';
	}
	else
	{
		ucDISP_Buf[9] = 'O';
		ucDISP_Buf[10] = 'N';
	}
#endif	
	
}
void UI_DMENU_Equalizer(void)
{
	unsigned char ucB[10];

	memset(&ucB[0], ' ', 10);
	
	switch  (ucAUDIO_Equalizer)
	{
		case EQ_OFF:
		#ifdef ST7565P	
			memcpy(&ucB[0],"EQ OFF",6);	
			ST7565_UpdateDisplayData(7, ucB[0]);	
			ST7565_UpdateDisplayData(16, ucB[1]);
			ST7565_UpdateDisplayData(31, ucB[3]);
			ST7565_UpdateDisplayData(41, ucB[4]);
			ST7565_UpdateDisplayData(49, ucB[5]);
		#endif
		#ifdef  PT6524
			memcpy(&ucDISP_Buf[3]," EQ OFF  ",9);
		#endif
			break;
		case EQ_CLASSIC:
		#ifdef ST7565P		
			memcpy(&ucB[0],"CLASSIC",7);						
			ST7565_UpdateDisplayData(7, ucB[0]);	
			ST7565_UpdateDisplayData(16, ucB[1]);
			ST7565_UpdateDisplayData(24, ucB[2]);
			ST7565_UpdateDisplayData(35, ucB[3]);
			ST7565_UpdateDisplayData(44, ucB[4]);
			ST7565_UpdateDisplayData(53, ucB[5]);
			ST7565_UpdateDisplayData(56, ucB[6]);
		#endif
		#ifdef  PT6524
			memcpy(&ucDISP_Buf[3]," CLASSIC ",9);
		#endif
			break;
		case EQ_COUNTRY:
		#ifdef ST7565P		
			memcpy(&ucB[0],"COUNTRY",7);
			ST7565_UpdateDisplayString(7, &ucB[0], 0);
		#endif
		#ifdef  PT6524
			memcpy(&ucDISP_Buf[3]," COUNTRY ",9);
		#endif
			break;
		case EQ_ROCK:
		#ifdef ST7565P
			memcpy(&ucB[0],"ROCK",4);
			ST7565_UpdateDisplayData(7, ucB[0]);	
			ST7565_UpdateDisplayData(16, ucB[1]);
			ST7565_UpdateDisplayData(26, ucB[2]);
			ST7565_UpdateDisplayData(35, ucB[3]);
		#endif
		#ifdef  PT6524
			memcpy(&ucDISP_Buf[3]," ROCK    ",9);
		#endif
			break;
		case EQ_JAZZ:
		#ifdef ST7565P
			memcpy(&ucB[0],"JAZZ",4);
			ST7565_UpdateDisplayData(7, ucB[0]);	
			ST7565_UpdateDisplayData(14, ucB[1]);
			ST7565_UpdateDisplayData(25, ucB[2]);
			ST7565_UpdateDisplayData(33, ucB[3]);
		#endif
		#ifdef  PT6524
			memcpy(&ucDISP_Buf[3]," JAZZ    ",9);
		#endif
			break;
		case EQ_POP:
		#ifdef ST7565P		
			memcpy(&ucB[0],"POP",3);
			ST7565_UpdateDisplayData(7, ucB[0]);	
			ST7565_UpdateDisplayData(16, ucB[1]);
			ST7565_UpdateDisplayData(26, ucB[2]);
		#endif
		#ifdef  PT6524
			memcpy(&ucDISP_Buf[3]," POP     ",9);
		#endif
			break;
		case EQ_VOICE:
		#ifdef ST7565P		
			memcpy(&ucB[0],"VOICE",5);
			ST7565_UpdateDisplayData(7, ucB[0]);	
			ST7565_UpdateDisplayData(16, ucB[1]);
			ST7565_UpdateDisplayData(26, ucB[2]);
			ST7565_UpdateDisplayData(29, ucB[3]);
			ST7565_UpdateDisplayData(38, ucB[4]);
		#endif
		#ifdef  PT6524
			memcpy(&ucDISP_Buf[3]," VOICE   ",9);
		#endif
			break;
	}
	
}

void UI_DMENU_Beep(void)
{	
#ifdef  MODEL_ARA5040
 	memcpy(&ucDISP_Buf[4], "BEEP", 4);
	
	if	(ucAUDIO_BeepEnable == 1)
	{
		ucDISP_Buf[9] = 'O';
		ucDISP_Buf[10] = 'N';
	}
	else
	{
		ucDISP_Buf[9] = 'O ';
		ucDISP_Buf[10] = 'F';
		ucDISP_Buf[11] = 'F';
	}
#else
	unsigned char ucB[10];

	memset(&ucB[0], ' ', 10);

	ucB[0] = 'B';
	ucB[1] = 'E';
	ucB[2] = 'E';
	ucB[3] = 'P';
	ucB[4] = ' ';	

	if  (ucAUDIO_BeepEnable == 1)
	{
		ucB[5] = 'O';
		ucB[6] = 'N';
		ucB[7] = 0x00;
	}
	else
	{
		ucB[5] = 'O';
		ucB[6] = 'F';
		ucB[7] = 'F';
		ucB[8] = 0x00;
	}
#ifdef  ST7565P
	ST7565_UpdateDisplayData(7, ucB[0]);
	ST7565_UpdateDisplayData(16, ucB[1]);
	ST7565_UpdateDisplayData(25, ucB[2]);	
	ST7565_UpdateDisplayData(34, ucB[3]);
	ST7565_UpdateDisplayString(47, &ucB[5], 0);	
#endif
#endif
}

void UI_DMENU_Scroll(void)
{
#ifdef  ST7565P

	unsigned char ucB[13];

	memset(&ucB[0], ' ', 13);

	ucB[0] = 'S';
	ucB[1] = 'C';
	ucB[2] = 'R';
	ucB[3] = 'O';
	ucB[4] = 'L';
	ucB[5] = 'L';
#ifdef  ST7565P
	ST7565_UpdateDisplayString(7, &ucB[0], 0);
#endif
	memset(&ucB[0], ' ', 13);

	if  (ucDISP_ScrollEnable == 1)
	{
		ucB[0] = 'O';
		ucB[1] = 'N';
	}
	else
	{
		ucB[0] = 'O';
		ucB[1] = 'F';
		ucB[2] = 'F';
	}	
#ifdef  ST7565P
	ST7565_UpdateDisplayString(62, &ucB[0], 0);
#endif
#endif
#ifdef  MODEL_ARA5040
	memcpy(&ucDISP_Buf[4], "SCRL", 4);

	if	(ucDISP_ScrollEnable == 1)
	{
		ucDISP_Buf[9] = 'O';
		ucDISP_Buf[10] = 'N';
	}
	else
	{
		ucDISP_Buf[9] = 'O';
		ucDISP_Buf[10] = 'F';
		ucDISP_Buf[11] = 'F';
	}
#endif
}

#ifdef  BLUETOOTH

void UI_DMENU_Bluetooth_Pair(void)
{
	unsigned char ucB[10];
	
	memset(&ucB[0], 0x00, 10);
	
	ucB[0] = 'B';
	ucB[1] = 'T';
	ucB[2] = ' ';
	ucB[3] = 'P';
	ucB[4] = 'A';
	ucB[5] = 'I';
	ucB[6] = 'R';
	
#ifdef  ST7565P
	ST7565_UpdateDisplayString(7, &ucB[0], 0);
#endif
}

void UI_DMENU_Bluetooth_Select(void)
{
	unsigned char ucB[10];
	
	memset(&ucB[0], 0x00, 10);

	ucB[0] = 'S';
	ucB[1] = 'E';
	ucB[2] = 'L';
	ucB[3] = 'E';
	ucB[4] = 'C';
	ucB[5] = 'T';
	
#ifdef  ST7565P
	ST7565_UpdateDisplayString(7, &ucB[0], 0);
#endif
}
void UI_DMENU_Bluetooth_Delete(void)
{
	unsigned char ucB[10];
	memset(&ucB[0], 0x00, 10);
		
	ucB[0] = 'D';
	ucB[1] = 'E';
	ucB[2] = 'L';
	ucB[3] = 'E';
	ucB[4] = 'T';
	ucB[5] = 'E';
		
#ifdef  ST7565P
	ST7565_UpdateDisplayString(7, &ucB[0], 0);
#endif

}
void UI_DMENU_Bluetooth_Volume(void)
{
	unsigned char ucB[10];
	memset(&ucB[0], 0x00, 10);
			
	ucB[0] = 'B';
	ucB[1] = 'T';
	ucB[2] = ' ';
	ucB[3] = 'V';
	ucB[4] = 'O';
	ucB[5] = 'L';
			
#ifdef  ST7565P
	ST7565_UpdateDisplayString(7, &ucB[0], 0);
#endif

}
void UI_DMENU_Bluetooth_PhoneBook(void)
{
	unsigned char ucB[12];
	memset(&ucB[0], 0x00, 12);
				
	ucB[0] = 'P';
	ucB[1] = 'h';
	ucB[2] = 'o';
	ucB[3] = 'n';
	ucB[4] = 'e';
	ucB[5] = ' ';
	ucB[6] = 'B';
	ucB[7] = 'o';
	ucB[8] = 'o';
	ucB[9] = 'k';
				
#ifdef  ST7565P
	ST7565_UpdateDisplayString(7, &ucB[0], 0);
#endif

}
void UI_DMENU_Bluetooth_OnOff(void)
{
	unsigned char ucB[10];
	memset(&ucB[0], 0x00, 10);
				
	ucB[0] = 'B';
	ucB[1] = 'T';
	ucB[2] = ' ';

	ucB[3] = 'O';
	ucB[4] = 'n';
	ucB[5] = '/';	
	ucB[6] = 'O';
	ucB[7] = 'f';
	ucB[8] = 'f';
				
#ifdef  ST7565P
	ST7565_UpdateDisplayString(7, &ucB[0], 0);
#endif
}

void UI_DMENU_Bluetooth_PairActive(void)
{
	unsigned char ucB[15];
	memset(&ucB[0], ' ', 15);
					
	ucB[0] = 'B';
	ucB[1] = 'T';
	ucB[2] = ' ';
	ucB[3] = 'P';
	ucB[4] = 'A';
	ucB[5] = 'I';
	ucB[6] = 'R';
	ucB[7] = 'I';
	ucB[8] = 'N';
	ucB[9] = 'G';
	
#ifdef  ST7565P
	ST7565_UpdateDisplayData(7, ucB[0]);
	ST7565_UpdateDisplayData(16, ucB[1]);
	ST7565_UpdateDisplayData(30, ucB[3]);
	ST7565_UpdateDisplayData(39, ucB[4]);
	ST7565_UpdateDisplayData(50, ucB[5]);
	ST7565_UpdateDisplayData(53, ucB[6]);
	ST7565_UpdateDisplayData(62, ucB[7]);
	ST7565_UpdateDisplayData(65, ucB[8]);
	ST7565_UpdateDisplayData(74, ucB[9]);
#endif

}
void UI_DMENU_Bluetooth_DeviceList(void)
{
	unsigned char ucBuf[BT_DEVICE_NAME_LENGTH + 10];
	unsigned char ucNum;

	memset(&ucBuf[0], 0x00, BT_DEVICE_NAME_LENGTH + 10);

	if  (ucMENU_CurNo == ucBT_DeviceCnt)
	{
		memcpy(&ucBuf[0], "PREVIOUS",8);
	#ifdef  ST7565P
		ST7565_UpdateDisplayData(7,ucBuf[0]);
		ST7565_UpdateDisplayData(16,ucBuf[1]);
		ST7565_UpdateDisplayData(25,ucBuf[2]);
		ST7565_UpdateDisplayData(34,ucBuf[3]);
		ST7565_UpdateDisplayData(43,ucBuf[4]);
		ST7565_UpdateDisplayData(46,ucBuf[5]);
		ST7565_UpdateDisplayData(56,ucBuf[6]);
		ST7565_UpdateDisplayData(65,ucBuf[7]);
	#endif
	}
	else
	{
		if  ((ucMENU_CurNo == 0) && (BT_ConnectStatus() == 1))
		{
			ST7565_UpdateDisplayImage(0, IMAGE_BT);
		}
		else
		{
			ucBuf[0] = (ucMENU_CurNo + 1) + '0';
			ucBuf[1] = '.';
			ucBuf[2] = ' ';
		#ifdef  ST7565P
			ST7565_UpdateDisplayString(0,&ucBuf[0],0);
		#endif
		}
		ucNum = BT_GetBDIndexByOrder(ucMENU_CurNo);
		memcpy(&ucBuf[3], &sBT_BDList[ucNum].ucName[0], BT_DEVICE_NAME_LENGTH);
	#ifdef  ST7565P
		ST7565_UpdateDisplayStringUnicode(13,&ucBuf[3],0,0xF3);
	#endif
	}

}

void UI_DMENU_Bluetooth_Icon_DeviceName(void)
{
	unsigned char ucBuf[40];

	memset(&ucBuf[0], 0x00, 40);
	ST7565_UpdateDisplayImage(0, IMAGE_BT);
	memcpy(&ucBuf[0], &sBT_BDList[ucBT_ConnectRequestIndex].ucName[0], BT_DEVICE_NAME_LENGTH);
#ifdef  ST7565P		
	ST7565_UpdateDisplayStringUnicode(12,&ucBuf[0],0,0xF3);
#endif
}

void UI_DMENU_Bluetooth_VolumeActive(void)
{	
	unsigned char ucBuf[10];
	
	memset(&ucBuf[0], ' ', 10);
	
	ucBuf[0] = 'B';
	ucBuf[1] = 'T';
	ucBuf[2] = ' ';
	ucBuf[3] = 'V';
	ucBuf[4] = 'O';
	ucBuf[5] = 'L';
	
	ucBuf[6] = (ucBT_Volume / 10) | '0';
	ucBuf[7] = (ucBT_Volume % 10) | '0';
	ucBuf[8] = 0x00;
			
#ifdef  ST7565P
	ST7565_UpdateDisplayData(7, ucBuf[0]);
	ST7565_UpdateDisplayData(16, ucBuf[1]);
	ST7565_UpdateDisplayData(30, ucBuf[3]);
	ST7565_UpdateDisplayData(39, ucBuf[4]);
	ST7565_UpdateDisplayData(49, ucBuf[5]);
		
	ST7565_UpdateDisplayString(62, &ucBuf[6], 0);
#endif

}
void UI_DMENU_Bluetooth_PhonebookRequest(void)
{
	unsigned char ucBuf[10];

	memset(&ucBuf[0], 0x00, 10);

	switch(ucMENU_CurNo)
	{
		case 0:
			memcpy(&ucBuf[0],"Down Load", 9);
		#ifdef  ST7565P
			ST7565_UpdateDisplayData(7, ucBuf[0]);
			ST7565_UpdateDisplayData(16, ucBuf[1]);
			ST7565_UpdateDisplayData(23, ucBuf[2]);
			ST7565_UpdateDisplayData(34, ucBuf[3]);
			ST7565_UpdateDisplayData(46, ucBuf[5]);
			ST7565_UpdateDisplayData(54, ucBuf[6]);
			ST7565_UpdateDisplayData(61, ucBuf[7]);
			ST7565_UpdateDisplayData(69, ucBuf[8]);
		#endif
			break;
		case 1:
			memcpy(&ucBuf[0],"DELETE", 6);
		#ifdef  ST7565P
			ST7565_UpdateDisplayData(14, ucBuf[0]);
			ST7565_UpdateDisplayData(23, ucBuf[1]);
			ST7565_UpdateDisplayData(32, ucBuf[2]);
			ST7565_UpdateDisplayData(40, ucBuf[3]);
			ST7565_UpdateDisplayData(49, ucBuf[4]);
			ST7565_UpdateDisplayData(58, ucBuf[5]);
		#endif
			break;
		case 2:
			memcpy(&ucBuf[0], "PREVIOUS",8);
		#ifdef  ST7565P
			ST7565_UpdateDisplayData(7,ucBuf[0]);
			ST7565_UpdateDisplayData(16,ucBuf[1]);
			ST7565_UpdateDisplayData(25,ucBuf[2]);
			ST7565_UpdateDisplayData(34,ucBuf[3]);
			ST7565_UpdateDisplayData(43,ucBuf[4]);
			ST7565_UpdateDisplayData(46,ucBuf[5]);
			ST7565_UpdateDisplayData(56,ucBuf[6]);
			ST7565_UpdateDisplayData(65,ucBuf[7]);
		#endif
			break;	
	}	
}

void UI_DMENU_Bluetooth_PhoneBookDownload(void)
{
	unsigned char ucBuf[14];
	
	memcpy(&ucBuf[0], "PB Down Load", 12);
	ucBuf[13] = 0x00;

	ST7565_UpdateDisplayString(0, &ucBuf[0], 0);
}

void UI_DMENU_Bluetooth_PhoneBookDelete(void)
{
	unsigned char ucBuf[10];
		
	memcpy(&ucBuf[0], "PB Delete", 9);
	ucBuf[9] = 0x00;

	ST7565_UpdateDisplayString(7, &ucBuf[0], 0);
}

void UI_DMENU_Bluetooth_ModeOnoff(void)
{
	unsigned char ucBuf[15];

	memset(&ucBuf[0], 0x00, 15);

	switch(ucMENU_CurNo)
	{
		case 0:
			if  (ucDISP_Blink == 0)
			{
				memcpy(&ucBuf[0], "BT ON", 5);
				#ifdef ST7565P
				ST7565_UpdateDisplayString(0, &ucBuf[0], 1);
				#endif
			}	
			break;
		case 1:
			if  (ucDISP_Blink == 0)
			{
				memcpy(&ucBuf[0], "BT OFF", 6);
				#ifdef ST7565P
				ST7565_UpdateDisplayString(0, &ucBuf[0], 1);
				#endif
			}	
			break;
		case 2:
			memcpy(&ucBuf[0], "PREVIOUS",8);
			#ifdef ST7565P
			ST7565_UpdateDisplayString(0, &ucBuf[0], 1);
			#endif
			break;		
	}
}

void UI_DMENU_Bluetooth_RecentCall(void)
{
	unsigned char ucBuf[41];

	memset(&ucBuf[0], 0x00, 41);

	if  (ucMENU_CurNo == ucPBAP_CallHistoryCnt)
	{
		memcpy(&ucBuf[0], "PREVIOUS",8);
	}
	else
	{
	/*	if  (Bluetooth_DISP_GetStringLentgh(&sPBAP_CallHistory[ucMENU_CurNo].ucName[0], 1, PBAP_NAME_BUFF_SIZE) != 0)
		{
			memcpy(&ucBuf[0],&sPBAP_CallHistory[ucMENU_CurNo].ucName[0],40);
		}
		else */if  (Bluetooth_DISP_CallNumberSize(&sPBAP_CallHistory[ucMENU_CurNo].ucHome[0], PBAP_NUMBER_BUFF_SIZE) != 0)
		{
			memcpy(&ucBuf[0],&sPBAP_CallHistory[ucMENU_CurNo].ucHome[0],20);
		}
		else if  (Bluetooth_DISP_CallNumberSize(&sPBAP_CallHistory[ucMENU_CurNo].ucWork[0], PBAP_NUMBER_BUFF_SIZE) != 0)
		{
			memcpy(&ucBuf[0],&sPBAP_CallHistory[ucMENU_CurNo].ucWork[0],20);
		}
		else if  (Bluetooth_DISP_CallNumberSize(&sPBAP_CallHistory[ucMENU_CurNo].ucCell[0], PBAP_NUMBER_BUFF_SIZE) != 0)
		{
			memcpy(&ucBuf[0],&sPBAP_CallHistory[ucMENU_CurNo].ucCell[0],20);
		}
		else if  (Bluetooth_DISP_CallNumberSize(&sPBAP_CallHistory[ucMENU_CurNo].ucOther[0], PBAP_NUMBER_BUFF_SIZE) != 0)
		{
			memcpy(&ucBuf[0],&sPBAP_CallHistory[ucMENU_CurNo].ucOther[0],20);
		} 
		else
		{
			memcpy(&ucBuf[0], "Private", 7);	
		}
	}

#ifdef ST7565P
	ST7565_UpdateDisplayString(0, &ucBuf[0], 0);
#endif
}

#endif

unsigned char MENU_DISP_Main(void)
{
	unsigned char ucRet = 1;

	if  (usMENU_Timer100msec == 0)		
	{
		ucMenuID = MENU_NONE;
	}

	switch  (ucMenuID)
	{
		case MENU_NONE:
			ucRet = 0;
			break;
		case MENU_CLOCK_SET_HOUR_ID:
			UI_DMENU_ClockSetHour();
			break;
		case MENU_CLOCK_SET_MIN_ID:
			UI_DMENU_ClockSetMin();
			break;
		case MENU_VOLUME_ID:
			DISP_Volume();
			break;
		case MENU_BASS_ID:
			UI_DMENU_Bass();
			break;
		case MENU_MIDDLE_ID:
			UI_DMENU_Middle();
			break;
		case MENU_TREBLE_ID:
			UI_DMENU_Treble();
			break;
		case MENU_FAD_ID:
			UI_DMENU_Fader();
			break;
		case MENU_BAL_ID:
			UI_DMENU_Balance();
			break;
		case MENU_LOUDNESS_ID:
			UI_DMENU_Loudess();
			break;
		case MENU_EQ_ID:
			UI_DMENU_Equalizer();
			break;
		case MENU_BEEP_ID:
			UI_DMENU_Beep();
			break;
		case MENU_SCROLL_ID:
			UI_DMENU_Scroll();
			break;
	#ifdef  BLUETOOTH
		case MENU_BT_PAIR_ID:
			UI_DMENU_Bluetooth_Pair();
			break;
		case MENU_BT_SEL_ID:
			UI_DMENU_Bluetooth_Select();
			break;
		case MENU_BT_DEL_ID:
			UI_DMENU_Bluetooth_Delete();
			break;
		case MENU_BT_VOL_ID:
			UI_DMENU_Bluetooth_Volume();
			break;
		case MENU_BT_PB_ID:
			UI_DMENU_Bluetooth_PhoneBook();
			break;
		case MENU_BT_MODE_ID:
			UI_DMENU_Bluetooth_OnOff();
			break;
		case MENU_BT_RECENT_ID:
			UI_DMENU_Bluetooth_RecentCall();
			break;		
		case MENU_BT_CONNETING_ID:
			UI_DMENU_Bluetooth_Icon_DeviceName();
			break;		
		case MENU_BT_VOL_ACTIVE_ID:
			UI_DMENU_Bluetooth_VolumeActive();
			break;	
		case MENU_BT_PAIR_ACTIVE_ID:
			UI_DMENU_Bluetooth_PairActive();
			break;
		case MENU_BT_SEL_LIST_ID:
		case MENU_BT_DEL_LIST_ID:
			UI_DMENU_Bluetooth_DeviceList();
			break;		
		case MENU_BT_PB_ACTIVE_ID:
			UI_DMENU_Bluetooth_PhonebookRequest();
			break;
		case MENU_BT_PB_ACTIVE_DOWNLOAD_ID:
			UI_DMENU_Bluetooth_PhoneBookDownload();
			break;
		case MENU_BT_PB_ACTIVE_DELETE_ID:
			UI_DMENU_Bluetooth_PhoneBookDelete();
			break;
		case MENU_BT_MODE_ACTIVE_ID:
			UI_DMENU_Bluetooth_ModeOnoff();
			break;			
	#endif
	}
	
	return(ucRet);
}

